package com.st.event.demo.strategy.impl;

import com.st.event.demo.source.EventAttribute;
import com.st.event.demo.strategy.StrategyFactory;
import com.st.event.demo.strategy.StrategyHandler;

import java.util.List;

public class StrategyHandlerFactory implements StrategyFactory {

    private final List<StrategyHandler> strategyHandlers;

    public StrategyHandlerFactory(List<StrategyHandler> strategyHandlers) {
        this.strategyHandlers = strategyHandlers;
    }

    @Override
    public StrategyHandler canApply(EventAttribute eventAttribute) {
        if (strategyHandlers == null || strategyHandlers.isEmpty()) {
            return null;
        }
        for (StrategyHandler strategyHandler : strategyHandlers) {
            if (strategyHandler.apply(eventAttribute)) {
                return strategyHandler;
            }
        }
        return null;
    }
}
